package com.ruoyi.project.note.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.SnowflakeIdWorker;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.note.domain.Note;
import com.ruoyi.project.note.service.INoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/note/upload")
public class UploadController extends BaseController {

    @Autowired
    private INoteService iNoteService;

    @PostMapping("/Images")
    public AjaxResult uploadDelta(@RequestBody Note note){
        Long id=note.getId();
        if (id==null){
            SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
            id = idWorker.nextId();
            note.setId(id);
            note.setCreateDate(DateUtils.getTime());
            return toAjax(iNoteService.insertNote(note));
        }else {
            note.setUpdateDate(DateUtils.getTime());
            return toAjax(iNoteService.updateNote(note));
        }
    }
}